Imports System.Collections

Partial Class pages_scribes_usercontrols_UCScribe : Inherits UserControl

#Region "Members"
    Private m_scribe As CScribe
    Private m_sortedList As IList
#End Region

#Region "Interface"
    Public Sub Display(ByVal [scribe] As CScribe, sortedList as IList)
        If Parent.Controls.Count Mod 2 = 0 Then row.Attributes.Add("class", "alt_row")

        m_scribe = [scribe]
        m_sortedList = sortedList

        With m_scribe
            litNumber.Text = CStr(sortedList.IndexOf(m_scribe) + 1)
            lnkScribeDisplayName.Text = .NameAndCountTruncated
            lnkScribeDisplayName.ToolTip = .ScribeContactName & vbCrLf & .ScribeDisplayName
            lnkScribeDisplayName.NavigateUrl = CSitemap.ScribeEdit(.ScribeId)
            lnkScribeDisplayWebsite.Text = CUtilities.Truncate(.ScribeDisplayWebsite)
            lnkScribeDisplayWebsite.ToolTip = .ScribeDisplayWebsite
            lnkScribeDisplayWebsite.NavigateUrl = .ScribeDisplayWebsite

            lnkTranscriptions.Text = CUtilities.CountSummary(.Products, "transcription", "none")
            lnkTranscriptions.NavigateUrl = CSitemap.ProductsForScribe(.ScribeId)

            lnkImages.Text = CUtilities.CountSummary(.ImageProducts, "image", "none")
            lnkImages.NavigateUrl = CSitemap.ProductsForScribe(.ScribeId)

            litScribeContactEmail.Text = .ScribeContactEmail
            litScribeContactEmail.NavigateUrl = "mailto:" & .ScribeContactEmail
            litScribeContactPhone.Text = .ScribeContactPhone
            litScribeBankAccount.Text = .ScribeBankAccount

            chkScribeForText.Checked = .ScribeForText
            chkScribeForImages.Checked = .ScribeForImages
        End With
    End Sub
#End Region

#Region "Event Handlers"
    Private Sub chkScribeForText_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkScribeForText.CheckedChanged
        With m_scribe
            .ScribeForText = chkScribeForText.Checked
            .Save()
        End With
        Refresh()
    End Sub
    Private Sub chkScribeForImages_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkScribeForImages.CheckedChanged
        With m_scribe
            .ScribeForImages = chkScribeForImages.Checked
            .Save()
        End With
        Refresh()
    End Sub
    Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnDelete.Click
        m_scribe.Delete()
        Refresh()
    End Sub
#End Region

#Region "Private"
    Private Sub Refresh()
        'CCache.ClearCache()

        'If False Then 'Request.RawUrl.ToLower.Contains("myparent.aspx") Then
        '    'Special case: Parent entity owns the list
        '    Response.Redirect(CSitemap.MyParentEdit(m_scribe.ScribeParentId, MyParent.ETab.scribes, m_pageIndex)
        'Else
        '    'Normal case: Search page owns the list
            Response.Redirect(Request.RawUrl) 'includes paging info
        'End If 
    End Sub
#End Region

End Class
